<template>
  <div class="preview-result">
    <div class="story-box">
      <div class="story-title linear-blue">
        <span class="icon"><icon-svg name="iconCalculateResult"></icon-svg></span><br />
        结果预览
      </div>
      <div class="story-content ">
        <div class="result-title">
          <el-row>
            <el-col :span="4" align="center"><span>更新周期</span></el-col>
            <el-col :span="4" align="center" v-if="!isAudit"><span>运行结果</span></el-col>
            <el-col :span="4" align="center"><span>创建方式</span></el-col>
            <el-col :span="4" align="center" v-if="!isAudit"><span>上次运行时间</span></el-col>
            <el-col :span="isAudit ? 16 : 8">
              <el-row>
                <el-col :span="12" align="center">
                  <span>客户标识</span>
                </el-col>
                <el-col :span="12" align="center">
                  <span>标签值</span>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </div>
        <div class="result-content">
          <el-row>
            <el-col :span="4" align="center">
              <div class="result-info-line">{{ $dict('$exec_frequency')[config.updateFrequency] }}</div>
            </el-col>
            <el-col :span="4" align="center" v-if="!isAudit">
              <div class="result-info-line">成功</div>
            </el-col>
            <el-col :span="4" align="center">
              <div class="result-info-line">规则创建-复合型指标</div>
            </el-col>
            <el-col :span="4" align="center" v-if="!isAudit">
              <div class="result-info-line">{{ config.updateTm }}</div>
            </el-col>
            <el-col :span="isAudit ? 16 : 8" align="center">
              <ul class="tag-scrollbar">
                <li v-for="item in showResult" :key="item.order">
                  <el-row>
                    <el-col :span="12" align="center">
                      {{ item.cust }}
                    </el-col>
                    <el-col :span="12" align="center">
                      {{ item.value }}
                    </el-col>
                  </el-row>
                </li>
              </ul>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    config: {
      type: Object,
      required: true,
      default: () => {}
    },
    isAudit: {
      // 是否审核组件调用，是的话隐藏时间
      type: Boolean,
      default: false
    }
  },
  computed: {
    showResult() {
      let result = []
      let previewResults =
        typeof this.config.previewResults === 'string'
          ? JSON.parse(this.config.previewResults)
          : this.config.previewResults
      if (this.config.previewResults) {
        previewResults.forEach(item => {
          result.push({ cust: item[0], value: item[1] })
        })
      }
      return result
    }
  },
  data() {
    return {}
  },
  methods: {}
}
</script>

<style lang="scss">
.preview-result {
  height: 300px;
  .el-col {
    word-break: break-all;
  }
  .result-info-line {
    font-size: 20px;
    font-weight: bold;
    height: 230px;
    padding-top: 90px;
    color: $tag-green;
  }
  .story-box {
    margin-top: 10px;
    height: 290px;
    border-radius: 5px;
    box-shadow: 1px 1px 3px #ddd, -1px -1px 3px #ddd;
    overflow: hidden;
    position: relative;
  }
  .story-title {
    font-size: 17px;
    font-weight: bold;
    width: 200px;
    height: 100%;
    color: #fff;
    text-align: center;
    position: relative;
    &:before {
      width: 100%;
      height: 100%;
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      background: url(~@/assets/img/params_bg.png) no-repeat 0px 0px/100% 100%;
    }
  }
  .icon {
    display: inline-block;
    width: 80px;
    height: 80px;
    background-color: #fff;
    margin: 80px 0 10px;
    border-radius: 50%;
    svg {
      width: 50px;
      height: 50px;
      margin-top: 15px;
    }
  }
  .linear-orange {
    background: linear-gradient(to bottom, #f3bf7c, #f3b172);
    svg {
      color: #f3b172;
    }
  }
  .linear-blue {
    background: linear-gradient(to bottom, #63a3fc, #5188ec);
    svg {
      color: #5188ec;
    }
  }
  .story-content {
    padding-left: 200px;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
  .result-title {
    font-weight: bold;
    height: 60px;
    border-bottom: 1px solid #eee;
    span {
      display: inline-block;
      width: 80%;
      height: 40px;
      line-height: 40px;
      margin: 10px 0 10px 0;
      background-color: #fcf5e5;
      border-radius: 20px;
    }
  }
  .result-content {
    height: calc(100% - 60px);
    .el-row,
    .el-col-8 {
      height: 100%;
    }
    ul {
      height: 100%;
      overflow-y: auto;
      li {
        height: 40px;
        line-height: 40px;
        text-align: center;
        .el-col {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
  }
}
</style>
